# Build recipe for icon
#
# Copyright 2016,2017 Mateus P. Rodrigues <mprodrigues@dragora.org>.
#
# This recipe is free software, under the terms of the Apache License 2.0

program=icon
version=v951
release=1

description="
Icon is a high-level, general-purpose programming language with novel features
including string scanning and goal-directed evaluation.
"

homepage=http://www.cs.arizona.edu/icon/
license="Public Domain"

tarname=${program}-${version}src.tgz
pkgname=${program}
pkgversion=9.5.1

# Remote source(s)
fetch=http://www2.cs.arizona.edu/icon/ftp/packages/unix/$tarname

# Source documentation
docs="README"
docsdir="${docdir}/${program}-${version}"

build() {
    unpack "${tardir}/$tarname"

    cd "$srcdir"src

    #The default Makefile makes some unreasonable things
    patch Makefile ${worktree}/patches/icon/Makefile.diff

    make Configure name=linux
    make -j${jobs}
    make Install bindir=/usr/bin \
    libdir=/usr/lib${libSuffix} \
    infodir=$infodir \
    mandir=$mandir \
    docdir=$docdir \
    dest="$destdir"

    # Compress and link man pages (if needed)
    if test -d "${destdir}/$mandir"
    then
        (
            cd "${destdir}/$mandir"
            find . -type f -exec lzip -9 '{}' +
            find . -type l | while read -r file
            do
                ln -sf "$(readlink -- "$file").lz" "${file}.lz"
                rm -- "$file"
            done
        )
    fi

    # Copy documentation
    mkdir -p "${destdir}${docsdir}"

    for file in $docs ; do
            cp -p $file "${destdir}${docsdir}"
	        done
}
